package com.ganmingshan.admin.controller;



import com.ganmingshan.admin.entity.SignEntity;
import com.ganmingshan.admin.entity.ToSignEntity;
import com.ganmingshan.admin.result.R;
import com.ganmingshan.admin.service.SignService;
import com.ganmingshan.admin.utils.ExcelUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;



@RestController
@RequestMapping("employee/sign")
public class SignController {
    @Autowired
    private SignService signService;
    @PostMapping("/list")
    public R list(@RequestBody SignEntity signEntity){
        List<SignEntity> list = signService.allList(signEntity.getLaterTime());
        return R.ok().put("list",list);
    }
    @GetMapping("/lateList")
    public R lateList(){
        List<SignEntity> list = signService.findLateList();
        return R.ok().put("list",list);
    }
    @GetMapping("/deptLater")
    public R deptLater(){
        HashMap<String,Long> counts = signService.deptLater();
        return R.ok().put("counts",counts );
    }
    @PostMapping("/uploadFile")
    public R uploadFile(@RequestPart("file")MultipartFile file) throws Exception{
        List<ToSignEntity> entities = ExcelUtils.readMultipartFile(file,ToSignEntity.class);
        signService.uploadExcel(entities);
        System.out.println(entities);
        return R.ok();
    }
    @GetMapping("/export")
    public void export(HttpServletResponse response){
        signService.export(response);
    }
}
